<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>5G+VR全景体验 - Panolens版本</title>
  <meta name="description" content="5G+VR全景体验 - VR物联网应用">
  <!-- 引入Three.js核心库 -->
  <script src="https://pchen66.github.io/js/three/three.min.js"></script>
  <!-- 引入Panolens.js库 -->
  <script src="https://pchen66.github.io/js/panolens/panolens.min.js"></script>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    
    body {
      font-family: Arial, sans-serif;
      overflow: hidden;
      height: 100vh;
      width: 100vw;
      background-color: #000;
    }
    
    #back-button {
      position: fixed;
      top: 20px;
      left: 20px;
      width: 50px;
      height: 50px;
      background-color: rgba(255, 255, 255, 0.8);
      border: none;
      border-radius: 50%;
      font-size: 24px;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 9999;
      box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
      transition: all 0.3s ease;
      user-select: none;
    }
    
    #back-button:hover {
      background-color: rgba(255, 255, 255, 1);
      transform: scale(1.1);
      box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    }
    
    #info-panel {
      position: fixed;
      bottom: 20px;
      left: 50%;
      transform: translateX(-50%);
      background-color: rgba(0, 0, 0, 0.7);
      color: white;
      padding: 15px 25px;
      border-radius: 8px;
      font-size: 14px;
      z-index: 9998;
      max-width: 90%;
      text-align: center;
    }
    
    #panorama-container {
      width: 100%;
      height: 100%;
    }
    
    /* 热点样式 */
    .hotspot {
      position: absolute;
      width: 30px;
      height: 30px;
      background-color: rgba(0, 102, 255, 0.8);
      border-radius: 50%;
      cursor: pointer;
      z-index: 10;
      transform: translate(-50%, -50%);
      box-shadow: 0 0 10px rgba(0, 102, 255, 0.8);
      animation: pulse 2s infinite;
    }
    
    @keyframes pulse {
      0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.8;
      }
      50% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 1;
      }
      100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.8;
      }
    }
    
    /* 文字标签样式 */
    .text-label {
      position: absolute;
      background-color: rgba(0, 0, 0, 0.7);
      color: white;
      padding: 8px 12px;
      border-radius: 4px;
      font-size: 14px;
      white-space: nowrap;
      z-index: 10;
      transform: translate(-50%, -50%);
      pointer-events: none;
    }
    
    /* 陀螺仪提示 */
    #gyro-notice {
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      background-color: rgba(0, 0, 0, 0.8);
      color: white;
      padding: 20px;
      border-radius: 10px;
      font-size: 16px;
      text-align: center;
      z-index: 9997;
      display: none;
    }
  </style>
</head>
<body>
  <button id="back-button" title="返回">←</button>
  <div id="info-panel">使用鼠标拖动查看全景 | 移动设备可旋转查看 | 注意：设备传感器需要HTTPS环境</div>
  <div id="gyro-notice">请点击屏幕允许设备方向访问</div>
  
  <!-- 全景容器 -->
  <div id="panorama-container"></div>
  
  <script>
    // 返回按钮点击事件
    document.getElementById('back-button').addEventListener('click', function() {
      console.log('点击返回按钮，返回发现页面');
      window.location.href = '/plugin/discovery/index.html';
    });
    
    // 键盘事件监听
    document.addEventListener('keydown', function(e) {
      if (e.key === 'Escape' || e.key === 'Backspace') {
        console.log('按下退出键，返回发现页面');
        window.location.href = '/plugin/discovery/index.html';
      }
    });
    
    // 初始化变量
    let panorama, viewer;
    let isGyroEnabled = false;
    const infoPanel = document.getElementById('info-panel');
    const gyroNotice = document.getElementById('gyro-notice');
    
  
    
    // 检查设备是否支持设备方向传感器
    function checkDeviceOrientationSupport() {
      if (!('DeviceOrientationEvent' in window)) {
        console.warn('当前浏览器不支持设备方向传感器');
        return false;
      }
      return true;
    }
    
    // 初始化全景
    function initPanorama() {
      console.log('初始化全景...');
      
      // 创建全景图像
      panorama = new PANOLENS.ImagePanorama('puydesancy.jpg');
      
      // 创建查看器
      viewer = new PANOLENS.Viewer({
        container: document.getElementById('panorama-container'),
        autoHideControls: false,
        enableReticle: true,
        dwellTime: 1500,
        autoRotate: false,
        autoRotateSpeed: 0.5
      });
      
      // 添加全景到查看器
      viewer.add(panorama);
      
      // 添加全景加载完成事件
      panorama.addEventListener('enter-fade-start', function() {
        console.log('全景加载完成');
      });
      
    }
    // 窗口大小变化时调整查看器大小
    window.addEventListener('resize', function() {
      if (viewer) {
        viewer.handleResize();
      }
    });
    
    // 页面加载完成后初始化全景
    window.addEventListener('load', initPanorama);
    
    // 清理函数，防止内存泄漏
    window.addEventListener('beforeunload', function() {
      if (viewer) {
        viewer.dispose();
      }
      window.removeEventListener('deviceorientation', handleDeviceOrientation);
    });
  </script>
</body>
</html>